package pub.wkq.user.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.web.bind.annotation.*;

import pub.wkq.api.controller.intercept.JWTCurrentUserInterceptor;
import pub.wkq.common.base.BaseInfoProperties;
import pub.wkq.common.result.JSONResult;
import pub.wkq.common.utils.MyInfo;
import pub.wkq.common.utils.SMSUtils;
import pub.wkq.common.utils.SerializationUtils;
import pub.wkq.pojo.Stu;
import pub.wkq.pojo.Users;
import pub.wkq.user.service.StuService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 王开琦
 * @since 2023-06-05
 */
@Slf4j
@RestController
@RequestMapping("stu")
public class StuController extends BaseInfoProperties {
    @Autowired
    private StuService stuService;
    @Resource
    private SMSUtils smsUtils;
    @Value("${jwt.key}")
    private String jwtKey;
    /**
     * 新增 Stu
     */
    @PostMapping("add")
    public JSONResult add(@RequestBody Stu stu, HttpServletRequest request) throws Exception {
        Users users = JWTCurrentUserInterceptor.currentUser.get();
        log.info("users = " + users);
        log.info("jwtKey {}" + jwtKey);
        stuService.add(stu);
        return JSONResult.ok();
    }

    public static void main(String[] args) throws IOException {
        Users users = new Users();
        users.setId("123");
        users.setNickname("wkq");
        users.setCreatedTime(LocalDateTime.now());
        users.setBirthday(LocalDate.now());
        users.setStartWorkDate(LocalDate.now());
        String s = SerializationUtils.serializeObject(users);
        System.out.println("s = " + s);
        Users users1 = SerializationUtils.deserializeObject(s, Users.class);
        System.out.println("users1 = " + users1);

    }
}

